]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Only respawn if gnome-shell exits abnormally
authorOwen W. Taylor <otaylor@fishsoup.net>
Mon, 24 Aug 2009 00:48:52 +0000 (20:48 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Tue, 25 Aug 2009 23:01:42 +0000 (19:01 -0400)
If Mutter exits with an exit status of 0, then that most likely
means that it was replaced by another window manager and we shoudln't
try to start the previous window manager and the panel.

(We don't actually know about the panel, but assume that if someone
is replacing us they know what they are doing.)

When Mutter exits with a signal, we know we want to restart.

When Mutter exits with a non-signal non-zero exit status, it's
ambiguous - we could be exiting because we lost the connection to
the X server, or because of a assertion failure in gnome-shell.
We assume the latter; if the X server is gone, all that will happen
is a bit of noise.

To know why Mutter exited accurately, we always wait() and
kill() the Mutter process, and then, if running in Xephyr, clean up
Xephyr afterwards. This has the nice side effect of exiting when
gnome-shell does and not forcing the user to close Xephyr manually.

http://bugzilla.gnome.org/show_bug.cgi?id=591171

src/gnome-shell.in

index ebb0f3957bb560bcd3c154f6f6f67a4e975dd6c7..ef15b95c38ad73d79e3b1a41142b37beb80ba5b2 100644 (file)
@@ -268,13 +268,19 @@ if options.debug:
     # later, in case we kill gdb at a bad time
     termattrs = termios.tcgetattr(0);
 
+# We only respawn the previous environment on abnormal exit;
+# for a clean exit, we assume that gnome-shell was replaced with
+# something else.
+normal_exit = False
+
 try:
     if run_in_xephyr:
-        shell = start_xephyr()
+        xephyr = start_xephyr()
         # This makes us not grab the org.gnome.Panel name
         os.environ['GNOME_SHELL_NO_REPLACE_PANEL'] = '1'
-        start_shell()
+        shell = start_shell()
     else:
+        xephyr = None
         if gnome_panel_pid is not None:
             kill_gnome_panel(gnome_panel_pid)
         shell = start_shell()
@@ -283,8 +289,6 @@ try:
     if options.verbose:
         print "Waiting for shell to exit"
     shell.wait()
-    if options.verbose:
-        print "Shell is dead"
 
 except KeyboardInterrupt, e:
     try:
@@ -292,14 +296,31 @@ except KeyboardInterrupt, e:
     except:
         pass
     shell.wait()
-    if options.verbose:
-        print "Shell killed"
-
 finally:
+    # Clean up Xephyr if it outlived the shell
+    if xephyr:
+        try:
+            os.kill(xephyr.pid, signal.SIGKILL)
+        except OSError:
+            pass
+
+    if shell.returncode ==  0:
+        normal_exit = True
+        if options.verbose:
+            print "Shell exited normally"
+    elif shell.returncode < 0:
+        # Python has no mapping for strsignal; not worth using
+        # ctypes for this.
+        print "Shell killed with signal %d" % - shell.returncode
+    else:
+        # Normal reason here would be losing connection the X server
+        if options.verbose:
+            print "Shell exited with return code %d" % shell.returncode
+
     if options.debug:
         termios.tcsetattr(0, termios.TCSANOW, termattrs);
 
-    if not run_in_xephyr:
+    if not run_in_xephyr and not normal_exit:
         # Restart gnome-panel and window manager
 
         # We don't want to start the new gnome-panel in the current